<?php
/* @var $this StkUsuarioController */
/* @var $model StkUsuario */
/* @var $form CActiveForm */
?>


<div class="form">
<div id="content2">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'Stk-usuario-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	  'enableAjaxValidation'=>false,
       'htmlOptions' => array('enctype' => 'multipart/form-data'),
       'enableClientValidation'=>true,
       'clientOptions'=>array(
       'validateOnSubmit'=>true,
            )
)); ?>

	<p class="note">Los campos marcados con <span class="required">*</span> son requeridos.</p>
	<?php $user=StkUsuario::model()->find('LOWER(NombreUsuario)=?',array( Yii::app()->user->name)); ?>
	<?php echo $form->errorSummary($model); ?>
	
	<?php if(!isset($user->id)){?>
		<div class="row">
		
			<?php echo $form->textField($model,'NombreUsuario',array('size'=>50,'maxlength'=>50, 'id'=>'NombreUsuario', 'class'=>'formulary_contact',  'value'=>'Nombre de Usuario','onblur'=>"if (this.value=='') this.value = 'Nombre de Usuario'", 'onfocus'=>"if (this.value=='Nombre de Usuario') this.value = ''",)); ?>
			<?php echo $form->error($model,'NombreUsuario'); ?>
		</div>

		<div class="row">
			<?php echo $form->textField($model,'repeat_password',array('maxlength'=>45, 'id'=>'Password', 'value'=>'Password', 'class'=>'formulary_contact','onfocus'=>"this.value=(this.value=='Password') ? '' : this.value;this.type='password'", 'onblur'=>"this.value=(this.value=='') ? 'Password' : this.value;this.type='password'")); ?>
			<?php echo $form->error($model,'Password'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->textField($model,'Password',array('size'=>45,'maxlength'=>45, 'class'=>'formulary_contact', 'value'=>'Repetir Password', 'class'=>'formulary_contact','onfocus'=>"this.value=(this.value=='Repetir Password') ? '' : this.value;this.type='password'", 'onblur'=>"this.value=(this.value=='') ? 'Repetir Password' : this.value;this.type='password'")); ?>
		</div>
	<?php }
		if(isset($user->id) && $model->NombreUsuario=="")
		{
		?>
			<div class="row">
		
			<?php echo $form->textField($model,'NombreUsuario',array('size'=>50,'maxlength'=>50, 'id'=>'NombreUsuario', 'class'=>'formulary_contact',  'value'=>'Nombre de Usuario','onblur'=>"if (this.value=='') this.value = 'Nombre de Usuario'", 'onfocus'=>"if (this.value=='Nombre de Usuario') this.value = ''",)); ?>
			<?php echo $form->error($model,'NombreUsuario'); ?>
		</div>

		<div class="row">
			<?php echo $form->textField($model,'repeat_password',array('maxlength'=>45, 'id'=>'Password', 'value'=>'Password', 'class'=>'formulary_contact','onfocus'=>"this.value=(this.value=='Password') ? '' : this.value;this.type='password'", 'onblur'=>"this.value=(this.value=='') ? 'Password' : this.value;this.type='password'")); ?>
			<?php echo $form->error($model,'Password'); ?>
		</div>
	
		<div class="row">
			<?php echo $form->textField($model,'Password',array('size'=>45,'maxlength'=>45, 'class'=>'formulary_contact', 'value'=>'Repetir Password', 'class'=>'formulary_contact','onfocus'=>"this.value=(this.value=='Repetir Password') ? '' : this.value;this.type='password'", 'onblur'=>"this.value=(this.value=='') ? 'Repetir Password' : this.value;this.type='password'")); ?>
		</div>
		<?php
		}
	if(isset($user->id) && $model->NombreUsuario!=""){?>
	<!--
		<div class="row">
			<?php echo CHtml::Button("Cambiar Contraseña", array('id'=>'change', 'name'=>'change', 'onclick'=>'js:Change();'));  ?>
		</div>
		<script type="javascript">
	
			function Change(){
			alert("hola");
				 $('#Password').attr('type', 'password');
			}
		
		</script>-->
		<div class="row">
			
			<?php echo $form->hiddenField($model,'repeat_password',array('maxlength'=>45, 'value'=>$user->Password)); ?>
			<?php echo $form->error($model,'Password'); ?>
		</div>
	
		<div class="row">
			
			<?php echo $form->hiddenField($model,'Password',array('size'=>45,'maxlength'=>45)); ?>
		</div>
	<?php } ?>
	<?php if($model->Nombres!="")
		{ ?>
	<div class="row">
		<?php echo $form->textField($model,'Nombres',array('size'=>50,'maxlength'=>50, 'class'=>'formulary_contact')); ?>
		<?php echo $form->error($model,'Nombres'); ?>
	</div>
	<?php }
			if($model->Apellidos!="")
			{?>
	<div class="row">
		<?php echo $form->textField($model,'Apellidos',array('size'=>50,'maxlength'=>50, 'class'=>'formulary_contact')); ?>
		<?php echo $form->error($model,'Apellidos'); ?>
	</div>
	<?php } ?>
	
	<?php if($model->Email!="")
			{?>
	<div class="row">
		<?php echo $form->textField($model,'Email', array('class'=>'formulary_contact'));?>
		<?php echo $form->error($model,'Email'); ?>
	</div>
	<?php } ?>

<!--
	<div class="row">
		<?php echo $form->labelEx($model,'EstaLinea'); ?>
		<?php echo $form->textField($model,'EstaLinea', array('class'=>'formulary_contact')); ?>
		<?php echo $form->error($model,'EstaLinea'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'EstaBloqueado'); ?>
		<?php echo $form->textField($model,'EstaBloqueado', array('class'=>'formulary_contact')); ?>
		<?php echo $form->error($model,'EstaBloqueado'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'FechaUltimoAcceso'); ?>
		<?php echo $form->textField($model,'FechaUltimoAcceso'); ?>
		<?php echo $form->error($model,'FechaUltimoAcceso'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'FechaUltimoBloqueo'); ?>
		<?php echo $form->textField($model,'FechaUltimoBloqueo'); ?>
		<?php echo $form->error($model,'FechaUltimoBloqueo'); ?>
	</div>

	<div class="row">
		<?php// echo $form->labelEx($model,'ErrorIntentarContraseña'); ?>
		<?php// echo $form->textField($model,'ErrorIntentarContraseña'); ?>
		<?php// echo $form->error($model,'ErrorIntentarContraseña'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'Aprobado'); ?>
		<?php echo $form->textField($model,'Aprobado'); ?>
		<?php echo $form->error($model,'Aprobado'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'FalloIntentoConexion'); ?>
		<?php echo $form->textField($model,'FalloIntentoConexion'); ?>
		<?php echo $form->error($model,'FalloIntentoConexion'); ?>
	</div>
-->
	<div class="row">
		<?php echo $form->labelEx($model,'Telefono'); ?>
		<?php
			$this->widget('CMaskedTextField', array(
				'model' => $model,
				'attribute' => 'Telefono',
				'mask' => '+58-___-_______',
				'charMap' => array('_'=>'[0-9]' , ','=>'[,]'),
				'htmlOptions' => array('size' => 20))
			);
		?>
		<?php echo $form->error($model,'Telefono'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'Genero'); ?>
		<?php echo $form->dropDownList($model,'Genero', array('Femenino'=>'Femenino','Masculino'=>'Masculino'));?>
		<?php echo $form->error($model,'Genero'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'FechaNacimiento'); ?>
		<?php
			if ($model->FechaNacimiento!='') {
		 		$model->FechaNacimiento=date('d-m-Y',strtotime($model->FechaNacimiento));
 			}
 			$this->widget('zii.widgets.jui.CJuiDatePicker', array(
 				'model'=>$model,
 				'attribute'=>'FechaNacimiento',
 				'value'=>$model->FechaNacimiento,
 				'language' => 'es',
 				'htmlOptions' => array('readonly'=>"readonly",'class'=>'formulary_contact'),
 
 				'options'=>array(
 					'autoSize'=>true,
 					'defaultDate'=>$model->FechaNacimiento,
 					'dateFormat'=>'yy-mm-dd',
 					'buttonImage'=>Yii::app()->baseUrl.'/images/calendario.png',
 					'buttonImageOnly'=>true,
 					'buttonText'=>'Fecha',
 					'selectOtherMonths'=>true,
 					'showAnim'=>'slide',
 					'showButtonPanel'=>true,
 					'showOn'=>'button',
 					'showOtherMonths'=>true,
 					'changeMonth' => 'true',
 					'changeYear' => 'true',
                                        'yearRange'=> '-100:+0',
                                   
                                    
 				),
 			));
		?>
		<?php echo $form->error($model,'FechaNacimiento'); ?>
	</div>
<!--
	<div class="row">
		<?php echo $form->labelEx($model,'NotificacionTiempoLimite'); ?>
		<?php echo $form->textField($model,'NotificacionTiempoLimite',array('size'=>20,'maxlength'=>20)); ?>
		<?php echo $form->error($model,'NotificacionTiempoLimite'); ?>
	</div>
-->
	<div class="row">
		<?php echo $form->labelEx($model,'NumeroDocumento'); ?>
		<?php echo $form->textField($model,'NumeroDocumento',array('size'=>20,'maxlength'=>20, 'class'=>'formulary_contact')); ?>
		<?php echo $form->error($model,'NumeroDocumento'); ?>
	</div>

	<div class="row">
		
		<?php 
		if(isset($user->id) && $user->Rol_Id==1){
		?>
		<?php echo $form->labelEx($model,'Rol_Id'); ?>
		<?php echo $form->dropDownList($model,'Rol_Id', CHtml::listData(StkRol::model()->findAll(), 'Id', 'Nombre'));?>
		<?php echo $form->error($model,'Rol_Id'); ?>
		<?php 
		}
		else
		{
			if(isset($user->id) && $user->Rol_Id==2)
			{
				echo $form->labelEx($model,'Rol_Id'); 
				$Criteria = new CDbCriteria();
				
                $Criteria->condition = "Id > 1";
				echo $form->dropDownList($model,'Rol_Id', CHtml::listData(StkRol::model()->findAll($Criteria), 'Id', 'Nombre'), array('class'=>'formulary_contact'));
			}
			else{
		?>
			<?php echo $form->hiddenField($model,'Rol_Id',array('type'=>"hidden",'readonly'=>"readonly", 'value'=>3)); ?>
			<?php echo $form->error($model,'Rol_Id'); ?>
		<?php
			}
		}
		 echo $form->hiddenField($model,'Estado',array('size'=>20,'maxlength'=>20,'value'=>'C'));
		 echo $form->error($model,'Estado');
		?>
	</div>

	<div class="row buttons">
		<?php
		//$model=new StkUsuario;
		echo CHtml::submitButton($model->isNewRecord ? 'Aceptar' : 'Guardar', array('class'=>'comment')); ?>
	</div>

<?php $this->endWidget(); ?>
</div>
</div><!-- form -->